package com.neuedu.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;


/**
 * @Author: MARK
 * @Date: 2019/7/25 20:09
 * @version: 1.0.0
 * @Description:
 */
@Slf4j
public class TestAop {
    public void beginMethod(JoinPoint joinPoint) {
        log.info("前置通知");
    }

    public void returning(JoinPoint joinPoint, Object value) {

        log.info("返回值通知, 返回结果为"+value);
    }

    public void exceptionMethod(JoinPoint joinPoint, Throwable ex) {
        log.info("异常通知, 异常为"+ex.getMessage());
    }

    public void finallyMethod(JoinPoint joinPoint) {
        log.info("最终通知, 不管有没有异常都会执行");
    }

    public Object aroundMethod(ProceedingJoinPoint proceedingJoinPoint) {
        log.info("当前运行方法为"+proceedingJoinPoint.getSignature().getName());
        log.info("当前方法参数为"+proceedingJoinPoint.getArgs());
        log.info("环绕通知");
        //执行方法
        try {
            long start = System.nanoTime();
            proceedingJoinPoint.proceed();
            long end = System.nanoTime();
            log.info("该方法运行时间为"+(end-start)+"ns");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return null;
    }
}
